package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchCourseTask;
import com.ruoyi.teach.service.ISchCourseTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程任务[作业和考试]Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/course_task")
public class SchCourseTaskController extends BaseController
{
    @Autowired
    private ISchCourseTaskService schCourseTaskService;

    /**
     * 查询课程任务[作业和考试]列表
     */
    @PreAuthorize("@ss.hasPermi('teach:course_task:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchCourseTask schCourseTask)
    {
        startPage();
        List<SchCourseTask> list = schCourseTaskService.selectSchCourseTaskList(schCourseTask);
        return getDataTable(list);
    }

    /**
     * 导出课程任务[作业和考试]列表
     */
    @PreAuthorize("@ss.hasPermi('teach:course_task:export')")
    @Log(title = "课程任务[作业和考试]", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchCourseTask schCourseTask)
    {
        List<SchCourseTask> list = schCourseTaskService.selectSchCourseTaskList(schCourseTask);
        ExcelUtil<SchCourseTask> util = new ExcelUtil<SchCourseTask>(SchCourseTask.class);
        util.exportExcel(response, list, "课程任务[作业和考试]数据");
    }

    /**
     * 获取课程任务[作业和考试]详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:course_task:query')")
    @GetMapping(value = "/{tId}")
    public AjaxResult getInfo(@PathVariable("tId") Long tId)
    {
        return AjaxResult.success(schCourseTaskService.selectSchCourseTaskByTId(tId));
    }

    /**
     * 新增课程任务[作业和考试]
     */
    @PreAuthorize("@ss.hasPermi('teach:course_task:add')")
    @Log(title = "课程任务[作业和考试]", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchCourseTask schCourseTask)
    {
        return toAjax(schCourseTaskService.insertSchCourseTask(schCourseTask));
    }

    /**
     * 修改课程任务[作业和考试]
     */
    @PreAuthorize("@ss.hasPermi('teach:course_task:edit')")
    @Log(title = "课程任务[作业和考试]", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchCourseTask schCourseTask)
    {
        return toAjax(schCourseTaskService.updateSchCourseTask(schCourseTask));
    }

    /**
     * 删除课程任务[作业和考试]
     */
    @PreAuthorize("@ss.hasPermi('teach:course_task:remove')")
    @Log(title = "课程任务[作业和考试]", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tIds}")
    public AjaxResult remove(@PathVariable Long[] tIds)
    {
        return toAjax(schCourseTaskService.deleteSchCourseTaskByTIds(tIds));
    }
}
